{% block sw_advanced_selection_rule %}
<sw-entity-advanced-selection-modal
    class="sw-advanced-selection-rule"
    entity-name="rule"
    :entity-display-text="$tc('global.sw-entity-advanced-selection-modal.entity.rule')"
    store-key="advancedSelection.rule"
    :entity-context="context"
    :entity-columns="columns"
    :entity-filters="filters"
    :criteria-aggregations="aggregations"
    :entity-associations="associations"
    :is-record-selectable-callback="isRecordSelectable"
    :disable-previews="true"
    empty-icon="solid-products"
    v-bind="$attrs"
    @selection-submit="$emit('selection-submit', $event)"
    @modal-close="$emit('modal-close', $event)"
>
    {% block sw_advanced_selection_rule__list_grid_columns_name %}
    <template #column-name="{ item }">
        {% block sw_advanced_selection_rule__list_grid_columns_name_content %}
        <span :class="getColumnClass(item)">
            {{ item.name }}
        </span>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_advanced_selection_rule__list_grid_columns_priority %}
    <template #column-priority="{ item }">
        {% block sw_advanced_selection_rule__list_grid_columns_priority_content %}
        <span :class="getColumnClass(item)">
            {{ item.priority }}
        </span>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_advanced_selection_rule__list_grid_columns_description %}
    <template #column-description="{ item }">
        {% block sw_advanced_selection_rule__list_grid_columns_description_content %}
        <span :class="getColumnClass(item)">
            {{ item.description }}
        </span>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_advanced_selection_rule_list_grid_columns_invalid %}
    <template #column-invalid="{item}">
        {% block sw_advanced_selection_rule_list_grid_columns_invalid_content %}
        <span :class="getColumnClass(item)">
            <template v-if="item.invalid">
                {{ $tc('sw-settings-rule.list.invalid') }}
            </template>
            <template v-else>
                {{ $tc('sw-settings-rule.list.valid') }}
            </template>
        </span>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_advanced_selection_rule_list_grid_columns_create_date %}
    <template #column-updatedAt="{item}">
        {% block sw_advanced_selection_rule_list_grid_columns_create_date_content %}
        <span :class="getColumnClass(item)">
            <template v-if="item.updatedAt">
                <sw-time-ago
                    :date="item.updatedAt"
                    :date-time-format="{ month: '2-digit', day: '2-digit' }"
                />
            </template>
            <template v-else>
                <sw-time-ago
                    :date="item.createdAt"
                    :date-time-format="{ month: '2-digit', day: '2-digit' }"
                />
            </template>
        </span>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_advanced_selection_rule_list_grid_columns_tags %}
    <template #column-tags="{ item }">
        <span :class="getColumnClass(item)">
            <span class="sw-data-grid__cell-value">
                <template v-if="item.tags.length > 0">
                    <sw-label
                        v-for="tag in item.tags"
                        :key="tag.id"
                        size="medium"
                    >
                        {% block sw_advanced_selection_rule_list_grid_columns_tags_content %}
                        {{ tag.name }}
                        {% endblock %}
                    </sw-label>
                </template>
                <template v-else>
                    -
                </template>
            </span>
        </span>
    </template>
    {% endblock %}

    {% block sw_advanced_selection_rule_list_grid_columns_assignments %}
    <template
        v-for="(propertyName, index) in assignmentProperties"
        #[`column-${propertyName}`]="{ item, aggregations }"
        :key="index"
    >
        <span
            class="sw-data-grid__cell-value"
        >
            {{ getCounts(item.id, aggregations)[propertyName] }}
            {{ $tc(`sw-settings-rule.list.assignments.${propertyName}`, getCounts(item.id, aggregations)[propertyName]) }}
        </span>
    </template>
    {% endblock %}
</sw-entity-advanced-selection-modal>
{% endblock %}
